# -*- coding: utf-8 -*-

''' Autor: Neuza Figueira '''

import numpy as np
import matplotlib.pyplot as plt

'''reference: http://matplotlib.sourceforge.net/examples/api/barchart_demo.html'''

'''Class that draws bar charts using matplotlib''' 
class drawGraphic:
    @staticmethod
    # Graphic about number of establishments per year
    def createGraphicStatistic1(database, establishment):
        theList = []
        for x in database.year:
            theList.append(database.countStatistic1(x, establishment))
            pass

        numberOfBars = len( database.year )
        teachersPerYear = tuple(theList)

        ind = np.arange(numberOfBars)
        width = 0.4       # the width of the bars

        plt.subplot(111)
        bars1 = plt.bar(ind + width * 3, teachersPerYear, width, color='g')

	plt.xlabel('Years')
        plt.ylabel('Number of teachers')
        plt.title('Graphic 1')

	# x bar scale
        plt.xticks(ind + width * 3 / 2, ('2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010') )

        # text labels
        def autolabel(bars):
            for bar in bars:
                height = bar.get_height()
                plt.text(bar.get_x() + bar.get_width()/2, 1 * height, '%d'%int(height),
                        ha='center', va='bottom')

        autolabel(bars1)
        plt.show()
        pass
    
    @staticmethod
    # Graphic about number of teachers divided per professional categories per establisment and per year
    def createGraphicStatistic2(database, establishment, categorie):
        theList = []
        for x in database.year:
            theList.append(database.countStatistic2(x, establishment, categorie))
            pass

        numberOfBars = len( database.year )
        teachersPerYear = tuple(theList)


        ind = np.arange(numberOfBars) 
        width = 0.4      

        plt.subplot(111)
        bars1 = plt.bar(ind + width * 3, teachersPerYear, width, color='g')

        plt.ylabel('Quantity of Teachers by Categorie')
        plt.xlabel('Years')
        plt.title('Graphic 2')
        plt.xticks(ind + width * 4 / 2, ('2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010') )


        # text labels
        def autolabel(bars):
            for bar in bars:
                height = bar.get_height()
                plt.text(bar.get_x() + bar.get_width()/2, 1 * height, '%d'%int(height),
                        ha='center', va='bottom')

        autolabel(bars1)
        plt.show

	pass



    
    @staticmethod
    def createGraphicStatistic3(database, establishment, degree, categorie):
        theList = []
        for x in database.year:
            theList.append(database.countStatistic3(x, establishment, degree, categorie))
            pass

        numberOfBars = len( database.year )
        teachersPerYear = tuple(theList)


        ind = np.arange(numberOfBars) 
        width = 0.4

        plt.subplot(111)
        bars1 = plt.bar(ind + width * 3, teachersPerYear, width, color='g')

        plt.ylabel('Quantity of Teachers by Degree')
        plt.xlabel('Years')
        plt.title('Graphic 3')
        plt.xticks(ind + width * 4 / 2, ('2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010') )



        # text labels
        def autolabel(bars):
            for bar in bars:
                height = bar.get_height()
                plt.text(bar.get_x()+bar.get_width() / 2, 1 * height, '%d'%int(height),
                        ha='center', va='bottom')

        autolabel(bars1)

        plt.show()
	pass
